/*
 * Copyright (c) 2005-2007 feyaSoft Corp. All Rights Reserved.
 */
package com.feyaSoft.plugin.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

/**
 * @author fzhuang
 * 
 * @Created at Nov 21, 2006
 * @Updated at Nov 21, 2006
 * 
 * Mobile.java is used to
 */
public class Mobile {
	public static boolean isMobile(HttpServletRequest request) {

		String userAccept = request.getHeader("accept");

		/*
		 * Check for the user's content type. If it suppots wml then we can show
		 * our mobile content for sure, if it does not but supports html then
		 * its a browser. -- This may not inclue all cases. --
		 * 
		 */
		if (userAccept.matches(".*?text/vnd\\.wap\\.wml.*?")) {
			return true;
		} else if (userAccept.matches(".*?text/html.*?")) {
			return false;
		}

		String userAgent = request.getHeader("user-agent");
		String mobileRegExp = ""; //(String) request.getSession().getServletContext()
//				.getAttribute(ServletAttribute.MOBILE_REG_EXP);
		Pattern pattern = Pattern.compile(mobileRegExp,
				Pattern.CASE_INSENSITIVE);
		Matcher matcher = pattern.matcher(userAgent);

		if (matcher.find()) {
			return false;
		}

		return true;

	}

}
